import Taro from "@tarojs/taro";
import { Toast } from '@nutui/nutui-react-taro'


const BASE_URL = "https://uat.hd.astraia.cn/";



// 封装网络请求函数
function request(options) {
  return new Promise((resolve, reject) => {
    Taro.request({
      url: BASE_URL + options.url,
      data: options.data || {},
      method: options.method || "GET",
      header: {
        "Content-Type": "application/json;charset=UTF-8",
        "Authorization":Taro.getStorageSync("token") 
      },
      timeout: 6000,
    })
      .then(res => {
        if (res.statusCode === 200) {
          resolve(res.data);
        } else {
          debugger
            Toast.show('test', {
              title: '提示',
              content: res.msg,
              type: 'fail',
              duration: 2,
              position: 'center',
              // icon: <Jd />,
              // lockScroll: true,
              // onClose: () => {
              //   console.log('close')
              // },
            })
          reject("网络请求失败");
        }
      })
      .catch(err => {
        reject(err);
      });
  });
}


export default request